<?php session_start(); ?>
<?php include "libfunc.php";?>
<?php if (!empty($_SESSION['admUser']) && !empty($_SESSION['admPass'])) { ?>
<html>
 <head>
  <title>.: Admin Room ClothingCorp :.</title>
  <link href="admInc/cssMainStyle.css" type="text/css" rel="stylesheet">
  <link href="admInc/cssTableStyle.css" type="text/css" rel="stylesheet">
  <link href="admInc/cssAdditionStyle.css" type="text/css" rel="stylesheet">
  <link href="admInc/cssTableNavigation.css" type="text/css" rel="stylesheet">
 </head>
 <body class="fix">
  <div id="wrapper">
   <div id="header">
    <div class="titleHeader"><center>
     <img src="image/logo2.png" border="0">
	</div><!-- titleHeader //-->
	<div class="subTitleHeader"><center>
	 - Website Administrator Control Panel -
	</div><!-- subTitleHeader //-->
   </div><!-- header //--></center>
   <div id="mainContent">
    <div id="leftColumn">
	 <div class="navigation">
	  <table border="0" width="100%" bgcolor="white">
	  <tr>
	    <td class="headerTable" align="center"><b>Admin Page</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="adminLayout.php"> Halaman Utama</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="newInformation.php"> Informasi Terkini</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="LogOut.php" onClick="return confirm('Apakah Anda benar-benar akan keluar dari halaman Admin ?')"> Keluar</a></td>
	  </tr>
	  <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Kategori</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="tambah_kategori.php"> Tambah Kategori</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_kategori.php"> View Kategori</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_kategori.php"> Pencarian Kategori</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Member</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="tambah_member.php"> Tambah Member</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_member.php"> View Member</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_member.php"> Pencarian Member</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Produk</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_produk.php"> View Produk</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_produk.php"> Pencarian Produk</a></td>
	  </tr>
	  <tr>
		<td></td>
	  </tr>
	  <tr>
		<td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Penjual</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="tambah_pejual.php"> Tambah Penjual</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_penjual.php"> View Penjual</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_penjual.php"> Pencarian Penjual</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
		<td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Pesanan</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_pesanan.php"> View Pesanan</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_pesanan.php"> Pencarian Pesanan</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  
	</table>
	 </div><!-- navigation //-->
	</div><!-- leftColumn //-->
	<div id="rightColumn">
	 <div class="content">
       	<?php 
		//----------- ambil value dari field cari dan keywordnya
		$fieldcari = $_POST['fieldcari'];
		$keyword   = $_POST['keyword'];
		
		//-------- koneksi ke database
		$link = koneksi_db();
		$sql  = "select * from produk where ";		
		
		//------- jika keyword id_produk
		if ($fieldcari == "id_produk") {
			$sql = $sql."id_produk = '$keyword'";
		}else if ($fieldcari == "judul"){
			$key = trim($keyword);  // menghilangkan spasi di kanan dan di kiri
			$pecah_keyword = explode(" ",$key);
			$jml_keyword = (integer)count($pecah_keyword);
			$jml_key = $jml_keyword - 1;
			
			for ($i = 0; $i <= $jml_key; $i++) {
			   $sql = $sql."judul like '%$pecah_keyword[$i]%'";
			   if ($i < $jml_key) {
				   $sql = $sql." OR ";
			   }
			}
			
		}else if ($fieldcari == "penjual"){
			$keyword = trim($keyword);  // menghilangkan spasi di kanan dan di kiri
			$pecah_keyword = explode(" ",$keyword);
			$jml_keyword = (integer)count($pecah_keyword);
			$jml_key = $jml_keyword - 1;
			
			for ($i = 0; $i <= $jml_key; $i++) {
			   $sql = $sql."penjual like '%$pecah_keyword[$i]%'";
			   if ($i < $jml_key) {
				   $sql = $sql." OR ";
			   }
			}
			
		}else if ($fieldcari == "deskripsi"){
			$keyword = trim($keyword);  // menghilangkan spasi di kanan dan di kiri
			$pecah_keyword = explode(" ",$keyword);
			$jml_keyword = (integer)count($pecah_keyword);
			$jml_key = $jml_keyword - 1;
			
			for ($i = 0; $i <= $jml_key; $i++) {
			   $sql = $sql."deskripsi like '%$pecah_keyword[$i]%'";
			   if ($i < $jml_key) {
				   $sql = $sql." OR ";
			   }
			}
			
		}else if ($fieldcari == "nama_penjual"){
			$sql = "select * from produk,penjual
			        where produk.id_penjual = penjual.id_penjual 
					and ";
			
			$keyword = trim($keyword);  // menghilangkan spasi di kanan dan di kiri
			$pecah_keyword = explode(" ",$keyword);
			$jml_keyword = (integer)count($pecah_keyword);
			$jml_key = $jml_keyword - 1;
			
			for ($i = 0; $i <= $jml_key; $i++) {
			   $sql = $sql."penjual.nama like '%$pecah_keyword[$i]%'";
			   if ($i < $jml_key) {
				   $sql = $sql." OR ";
			   }
			}
						
		}else if ($fieldcari == "nama_kategori"){
			$sql = "select * from produk,kategori
			        where produk.id_kategori = kategori.id_kategori
					and ";
			
			$keyword = trim($keyword);  // menghilangkan spasi di kanan dan di kiri
			$pecah_keyword = explode(" ",$keyword);
			$jml_keyword = (integer)count($pecah_keyword);
			$jml_key = $jml_keyword - 1;
			
			for ($i = 0; $i <= $jml_key; $i++) {
			   $sql = $sql."kategori.nama like '%$pecah_keyword[$i]%'";
			   if ($i < $jml_key) {
				   $sql = $sql." OR ";
			   }
			}
		}
		
		
		  $res  = mysql_query($sql,$link);
		  $banyakrecord = mysql_num_rows($res);
				
		  if($banyakrecord>0){
		  ?>
		    <fieldset>
             <legend>Hasil Pencarian Data Produk</legend>
             <table align='center' class="tableView">
		  	   <tr class='trTable'>
		        <td>NO</td>
		   	 	<td>Judul</td>
				<td>Nama Penjual</td>
			 	<td>Nama Kategori</td>
			 	<td>Penjual</td>
			 	<td>Detail</td>
			   </tr>
	  	  <?php
	      $i=0;
		  while( $data = mysql_fetch_array($res) ){
		    $i++;
		    ?>
		       <tr>
		        <td><?php echo $i; ?></td>
			 	<td><?php echo $data['judul']; ?></td>
			 	<td>
			   <?php
			     $sql_p = "select penjual.nama from penjual,produk
				 		    where penjual.id_penjual = produk.id_penjual
							and
							produk.id_penjual = '$data[id_penjual]'
							";
				 $query_p = mysql_query($sql_p,$link);
				 $hasil_p = mysql_fetch_array($query_p);
				 
				 echo $hasil_p['nama'];
			   ?>
             </td>
			 <td>
			   <?php 
			   	  $sql_k = "select kategori.nama from kategori,produk
				 		    where kategori.id_kategori = produk.id_penerbit
							and
							produk.id_kategori = '$data[id_kategori]'
							";
				 $query_k = mysql_query($sql_k,$link);
				 $hasil_k = mysql_fetch_array($query_k);
				 
				 echo $hasil_k['nama'];
			   ?>
             </td>
			 	<td><?php echo $data['penjual']; ?></td>
			 	<td align="center"><a href="detail_produk.php?id=<?php echo $data['id_produk']; ?>"><img src="image/magnifier.png" border="0" title="Lihat !"></a></td>
               </tr>
			 
		  <?php
		  }
		  ?>
            </table>
            </fieldset>
          	<div id="keterangan">
       		 <fieldset>
         	  <legend>Keterangan</legend>
         	   Hanya ada  <?php echo $banyakrecord; ?> produk dari hasil pencarian !!!<br><br>
               <input type="button" onClick="javascript:history.back()" value="Cari Lagi !">
       		 </fieldset>
     		</div>
	    <?php
        }else{?>
			 <div id='keterangan'>
			  <fieldset>
			   <legend>Keterangan</legend>
			    Data Yang Dicari Tidak ditemukan!!!<br><br>
                <input type="button" onClick="javascript:history.back()" value="Cari Lagi !">
			   </fieldset>
			 </div>
         <?php
        }
		?>
     </div><!-- content //-->
	</div><!-- rightColumn //-->
   </div><!-- mainContent //-->
  </div><!-- wrapper //-->
 </body>
</html>
<?php
}else{
  echo "<script language='javascript'>alert('Silakan Sign In Terlebih Dahulu')</script>";
  echo "<script language='javascript'>window.location = '../admin/'</script>";
}